package com.fh.role.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.fh.result.ResultObject;
import com.fh.role.entity.UmsRole;
import com.fh.role.service.IUmsRoleService;
import com.fh.search.SearchRole;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台用户角色表 前端控制器
 * </p>
 *
 * @author F
 * @since 2021-05-13
 */
@RestController
@RequestMapping("/ums/role")
public class UmsRoleController {

    @Autowired
    private IUmsRoleService roleService;


    @GetMapping
    public IPage<UmsRole> queryRoleList(Page<UmsRole> page, SearchRole role){
        QueryWrapper queryWrapper=new QueryWrapper<>();
        if (StringUtils.isNotBlank(role.getName())){
            queryWrapper.like("name",role.getName());
        }
        return roleService.page(page,queryWrapper);
    }
    @DeleteMapping
    public ResultObject batchDelRole(@RequestBody List<Long> roleIds){
        roleService.removeByIds(roleIds);
        return ResultObject.success();
    }
    @DeleteMapping("/{roleId}")
    public ResultObject deleteRole(@PathVariable("roleId")Long roleId){
        roleService.removeById(roleId);
        return ResultObject.success();
    }
    @PostMapping
    public ResultObject saveOrUpdateRole(@RequestBody UmsRole role){
        roleService.saveOrUpdateRole(role);
        return ResultObject.success();
    }

    @GetMapping("/{roleId}")
    public ResultObject getRoleById(@PathVariable("roleId") Long roleId){
        UmsRole role= roleService.getById(roleId);
        return ResultObject.success(role);
    }
    //查角色条数
    @GetMapping("/all")
    public ResultObject queryRoleListAll(){
        List<UmsRole>list=roleService.list();
        return ResultObject.success(list);
    }




}
